package org.quipu.domain;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name = "BOOK_USERS", uniqueConstraints = @UniqueConstraint(columnNames = {"ID_USER", "ID_BOOK"}))
public class BookUser extends UniqueEntity implements Serializable {

    @JoinColumn(name = "ID_USER", referencedColumnName = "ID", nullable = true)
    @ManyToOne
    private User user;

    @JoinColumn(name = "ID_BOOK", referencedColumnName = "ID", nullable = false)
    @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST})
    private Book book;

    @Column(name = "IS_OWNER")
    private Boolean owner;

    @Column(name = "IS_READONLY")
    private Boolean readonly;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Book getBook() {
        return book;
    }

    public void setBook(Book book) {
        this.book = book;
    }

    public Boolean getOwner() {
        return owner;
    }

    public void setOwner(Boolean owner) {
        this.owner = owner;
    }

    public Boolean getReadonly() {
        return readonly;
    }

    public void setReadonly(Boolean readonly) {
        this.readonly = readonly;
    }
}
